﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace C_sports_meet.Volunteer
{
    /// <summary>
    /// VQuery.xaml 的交互逻辑
    /// </summary>
    public partial class VQuery : Page
    {
        public VQuery()
        {
            this.MaxWidth = this.MinWidth = 850;
            this.MaxHeight = this.MinHeight = 434.76;
            InitializeComponent();
        }

        private void Button1_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string strCon = "server=.;database=sportmeet;user=sa;pwd=Lss200217";
                SqlConnection con = new SqlConnection(strCon);
                string strSql1 = "select * from vapply where vno = '" + Text1.Text + "' and eno='" + Text2.Text + "';";
                SqlCommand cmd1 = new SqlCommand(strSql1, con);
                con.Open();
                int i = cmd1.ExecuteNonQuery();
                if (i == 1)
                {
                    string strSql2 = "select * from vapply where vno = '" + Text1.Text + "'  and   eno = '" + Text2.Text + "' and whetherentry = '是';";
                    SqlCommand cmd2 = new SqlCommand(strSql2, con);
                    int k = cmd2.ExecuteNonQuery();
                    if (k == 1)
                    {
                        MessageBox.Show("报名成功，已被录取");
                    }
                    else
                    {
                        MessageBox.Show("报名成功，还未被被录取");
                    }
                }
                else
                {
                    MessageBox.Show("报名未成功");
                }
                con.Close();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        private void BtnSelect1_Click(object sender, RoutedEventArgs e)
        {
            string strCon = "server=.;database=sportmeet;user=sa;pwd=Lss200217";
            SqlConnection con = new SqlConnection(strCon);
            string strSql = "select * from eevent where fno='202207001'";
            SqlCommand cmd = new SqlCommand(strSql, con);
            con.Open();
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            DataTable dataTable = new DataTable();
            adapter.Fill(dataTable);
            DataGrid1.ItemsSource = dataTable.DefaultView;
            con.Close();
        }

        private void BtnSelect2_Click(object sender, RoutedEventArgs e)
        {
            string strCon = "server=.;database=sportmeet;user=sa;pwd=Lss200217";
            SqlConnection con = new SqlConnection(strCon);
            string strSql = "select * from eevent where fno='202207002'";
            SqlCommand cmd = new SqlCommand(strSql, con);
            con.Open();
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            DataTable dataTable = new DataTable();
            adapter.Fill(dataTable);
            DataGrid1.ItemsSource = dataTable.DefaultView;
            con.Close();
        }

        private void BtnSelect3_Click(object sender, RoutedEventArgs e)
        {
            string strCon = "server=.;database=sportmeet;user=sa;pwd=Lss200217";
            SqlConnection con = new SqlConnection(strCon);
            string strSql = "select * from eevent where fno='202207003'";
            SqlCommand cmd = new SqlCommand(strSql, con);
            con.Open();
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            DataTable dataTable = new DataTable();
            adapter.Fill(dataTable);
            DataGrid1.ItemsSource = dataTable.DefaultView;
            con.Close();
        }

        private void BtnSelect4_Click(object sender, RoutedEventArgs e)
        {
            string strCon = "server=.;database=sportmeet;user=sa;pwd=Lss200217";
            SqlConnection con = new SqlConnection(strCon);
            string strSql = "select * from eevent where fno='202207004'";
            SqlCommand cmd = new SqlCommand(strSql, con);
            con.Open();
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            DataTable dataTable = new DataTable();
            adapter.Fill(dataTable);
            DataGrid1.ItemsSource = dataTable.DefaultView;
            con.Close();
        }

        private void Button2_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                DataRowView mySelectedElement = (DataRowView)DataGrid1.SelectedItem;
                string result = mySelectedElement.Row[0].ToString();
                string strCon = "server=.;database=sportmeet;user=sa;pwd=Lss200217";
                SqlConnection con = new SqlConnection(strCon);
                con.Open();
                string strSql = "select count(*) from vapply where eno= '" + result + "'";
                SqlCommand cmd2 = new SqlCommand(strSql, con);

                SqlDataAdapter adapter = new SqlDataAdapter(cmd2);
                DataTable dataTable = new DataTable();
                adapter.Fill(dataTable);
                string count = dataTable.Rows[0][0].ToString();
                label1.Content = "报名人数：" + count;
                con.Close();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }


    }
}